package com.ruoyi.web.controller.veterinary;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.veterinary.domain.VetBillDetail;
import com.ruoyi.veterinary.service.IVetBillDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账单明细Controller
 * 
 * @author ruoyi
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/veterinary/billDetail")
public class VetBillDetailController extends BaseController
{
    @Autowired
    private IVetBillDetailService vetBillDetailService;

    /**
     * 查询账单明细列表
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(VetBillDetail vetBillDetail)
    {
        startPage();
        List<VetBillDetail> list = vetBillDetailService.selectVetBillDetailList(vetBillDetail);
        return getDataTable(list);
    }

    /**
     * 导出账单明细列表
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:export')")
    @Log(title = "账单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VetBillDetail vetBillDetail)
    {
        List<VetBillDetail> list = vetBillDetailService.selectVetBillDetailList(vetBillDetail);
        ExcelUtil<VetBillDetail> util = new ExcelUtil<VetBillDetail>(VetBillDetail.class);
        util.exportExcel(response, list, "账单明细数据");
    }

    /**
     * 获取账单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(vetBillDetailService.selectVetBillDetailByDetailId(detailId));
    }

    /**
     * 获取账单的所有明细
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:query')")
    @GetMapping(value = "/byBillId/{billId}")
    public AjaxResult getDetailsByBillId(@PathVariable("billId") Long billId)
    {
        List<VetBillDetail> list = vetBillDetailService.selectVetBillDetailByBillId(billId);
        return success(list);
    }

    /**
     * 新增账单明细
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:add')")
    @Log(title = "账单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VetBillDetail vetBillDetail)
    {
        return toAjax(vetBillDetailService.insertVetBillDetail(vetBillDetail));
    }

    /**
     * 修改账单明细
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:edit')")
    @Log(title = "账单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VetBillDetail vetBillDetail)
    {
        return toAjax(vetBillDetailService.updateVetBillDetail(vetBillDetail));
    }

    /**
     * 删除账单明细
     */
    @PreAuthorize("@ss.hasPermi('veterinary:billDetail:remove')")
    @Log(title = "账单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(vetBillDetailService.deleteVetBillDetailByDetailIds(detailIds));
    }
}